home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / STRING.C < prev    next >
Text File  |  1994-07-22  |  1KB  |  66 lines

  1. /*
  2.  
  3.     String class definition for GCOOPE 1.0
  4.  
  5.     Designed 7/21/94 by Brian L. Price
  6.  
  7.     Compatible with experimental strong typing option.
  8.  
  9.     Released as Public Domain   July, 1994.
  10.  
  11. */
  12.  
  13.  
  14. #define CLASS String
  15.  
  16. #include "gcoope10.h"
  17. #include <string.h>
  18.  
  19. object CLASS;
  20.  
  21. extern object Array;
  22. extern object LowStream;
  23. extern object Dynmem;
  24.  
  25. USEGEN(reSize);
  26. USEGEN(addressOf);
  27. USEGEN(lengthOf);
  28. USEGEN(changeVal);
  29. USEGEN(sizeOf);
  30. USEGEN(asString);
  31.  
  32. cmethod object m4New(object instance, char * text)
  33. {
  34. char *  ptrA;
  35.  
  36. if(NULL==makeInst(&instance)) return FUNCFAIL;
  37. g(New)(ST(Array), (word) sizeof(char), (word) strlen(text)+1);
  38. g(New)(ST(LowStream));
  39. ptrA=((VDPTRRV) g)(GEN(addressOf))(instance);
  40. strcpy(ptrA, text);
  41. return instance;
  42. }
  43.  
  44.  
  45. imethod object m4changeVal(object instance, char * newText)
  46. {
  47. char *     ptrA;
  48. int     length;
  49.  
  50. g(GEN(reSize))(instance, (word) length=strlen(newText));
  51. ptrA=((VDPTRRV) g)(GEN(addressOf))(instance);
  52. strncpy(ptrA, newText, length);
  53. return FUNCOKAY;
  54. }
  55.  
  56.  
  57. CLASS_INSTALL
  58. {
  59. if( END==(CLASS=g(New)(Class, 0, 0, Array, LowStream, END))
  60.     || addGMthd(CLASS, New, (method) m4New)
  61.     || ADDGM(changeVal) || RENGM(sizeOf, Dynmem, lengthOf)
  62.     || addGMthd(CLASS, GEN(asString), bounceBack))
  63.     return FUNCFAIL;
  64. return FUNCOKAY;
  65. }
  66.